﻿#include "treeitem2.h"
#include "common.h"

TreeItem::TreeItem(TreeItem *parent) : _parent(parent), _type(UNKNOWN), _ptr(nullptr), _row(-1)
{
}

TreeItem::~TreeItem()
{
    removeChildren();
}

// 在本节点下添加子节点
void TreeItem::addChild(TreeItem *item)
{
    item->setRow(_children.size());
    _children.append(item);
}

// 清空所有子节点
void TreeItem::removeChildren()
{
    qDeleteAll(_children);
    _children.clear();
}

// 获取本节点第column列的数据
QVariant TreeItem::data(int column) const
{
    Department *department = (Department *)_ptr;
    switch (column)
    {
    case COLUMN_NAME:
        return department->name;
    case COLUMN_ID:
        return department->id;
    case COLUMN_NUM:
        return department->number;
    case COLUMN_OrganizationName:
        return department->preOrganizationName;
    default:
        return QVariant();
    }

    return QVariant();
}
